/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.Entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * 
 * @author KIS
 */
@Entity
@Table(name = "article", catalog = "Final_Project_Sem_IV", schema = "dbo")
@XmlRootElement
@NamedQueries({ @NamedQuery(name = "Article.findAll", query = "SELECT a FROM Article a"), @NamedQuery(name = "Article.findById", query = "SELECT a FROM Article a WHERE a.id = :id"),
		@NamedQuery(name = "Article.findByTitle", query = "SELECT a FROM Article a WHERE a.title = :title"), @NamedQuery(name = "Article.findByHtmlContent", query = "SELECT a FROM Article a WHERE a.htmlContent = :htmlContent"),
		@NamedQuery(name = "Article.findByPublishDate", query = "SELECT a FROM Article a WHERE a.publishDate = :publishDate"), @NamedQuery(name = "Article.findByRatingStars", query = "SELECT a FROM Article a WHERE a.ratingStars = :ratingStars"),
		@NamedQuery(name = "Article.findByRatingTimes", query = "SELECT a FROM Article a WHERE a.ratingTimes = :ratingTimes") })
public class Article implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@NotNull
	@Column(name = "id", nullable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 300)
	@Column(name = "title", nullable = false, length = 300)
	private String title;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 1073741823)
	@Column(name = "htmlContent", nullable = false, length = 1073741823)
	private String htmlContent;
	@Basic(optional = false)
	@NotNull
	@Column(name = "publishDate", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date publishDate;
	@Column(name = "ratingStars")
	private Integer ratingStars;
	@Column(name = "ratingTimes")
	private Integer ratingTimes;
	@JoinColumn(name = "authorID", referencedColumnName = "id")
	@ManyToOne
	private CompanyUser authorID;
	@JoinColumn(name = "articleCategoryID", referencedColumnName = "id")
	@ManyToOne
	private ArticleCategory articleCategoryID;

	public Article() {
	}

	public Article(Integer id) {
		this.id = id;
	}

	public Article(Integer id, String title, String htmlContent, Date publishDate) {
		this.id = id;
		this.title = title;
		this.htmlContent = htmlContent;
		this.publishDate = publishDate;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getHtmlContent() {
		return htmlContent;
	}

	public void setHtmlContent(String htmlContent) {
		this.htmlContent = htmlContent;
	}

	public Date getPublishDate() {
		return publishDate;
	}

	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	public Integer getRatingStars() {
		return ratingStars;
	}

	public void setRatingStars(Integer ratingStars) {
		this.ratingStars = ratingStars;
	}

	public Integer getRatingTimes() {
		return ratingTimes;
	}

	public void setRatingTimes(Integer ratingTimes) {
		this.ratingTimes = ratingTimes;
	}

	public CompanyUser getAuthorID() {
		return authorID;
	}

	public void setAuthorID(CompanyUser authorID) {
		this.authorID = authorID;
	}

	public ArticleCategory getArticleCategoryID() {
		return articleCategoryID;
	}

	public void setArticleCategoryID(ArticleCategory articleCategoryID) {
		this.articleCategoryID = articleCategoryID;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Article)) {
			return false;
		}
		Article other = (Article) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "com.Entity.Article[ id=" + id + " ]";
	}

}
